package practise.sort.SortAlgrothim;

public class FindMinPartition extends SortUtil {

    static public int getPartitionIndex(int[] arrays, int expected){
        int index=0;
        int right=arrays.length-1;
        while(index<=right&&right>0&&index<arrays.length){
            if(arrays[index]==expected){
                index++;
            }
            if(arrays[index]>expected){
                swap(arrays,index,right--);
            }
            if(arrays[index]<expected){
                swap(arrays,index+1,index++);
            }
        }
        return index-1;
    }

    static public int partitionByEndNum(int[] arrays,int start, int end){
        if(start>=end){
            return 0;
        }
        int index = end ;
        end--;

        for(; start<end;) {
            if(arrays[index]==arrays[end]){
                index--;
                end--;
            }
            if(arrays[index]<arrays[end]){
                swap(arrays,end,start++);
            }
            else{
                 swap(arrays,end,index--);
            }
        }
        return end++;
    }

}
